<?php

define('LOG_LVL_NONE',      0x00);

define('LOG_LVL_INPUT',     0x01);
define('LOG_LVL_APPL',      0x02);
define('LOG_LVL_DBINTFCE',  0x04);
define('LOG_LVL_SQL',       0x08);

define('LOG_LVL_ALL',       0xff);



/**
 * Description of Debug
 *
 * @author GHoogendoorn
 * @version 0.1
 * 
 * Version history
 * 0.1  GHoogendoorn    Initial version
 */
class Debug {
    
    private $loglevel = LOG_LVL_ALL;
    private $log_aan = FALSE;

    public function __construct($loglvl = TRUE) {
        //Initialisatie
        
        
    }
    
    public function debugOff(){
        $this->loglevel = LOG_LVL_NONE;
    }
    
    public function setLogLvl( $lvl ){
        if ( !is_int($lvl)){
            return FALSE;
        }
        
        $this->loglevel |= $lvl; 
    }

    public function  checkLogLvl($lvl) {
        
        if( !is_int($lvl)){
            return FALSE;
        }
        
        if ( $this->loglevel & $lvl){
            return TRUE;
        }
        
        
        return FALSE;
    }
    
    public function trace($tekst, $loglvl){
        if( $this->checkLogLvl($loglvl)){
            echo $tekst;
        }
    }

}

class TestDebug {

    public function TestDebug() {
        
        echo "****************** Test Debug ****************<br />";
        try {
            $test = new Debug();
            
            $test->trace("Dit is input trace tekst<br />", LOG_LVL_INPUT);
            
            $test->trace("Dit is db interface trace tekst<br />", LOG_LVL_DBINTFCE);
            
            $test->trace("Dit is SQL trace tekst<br />", LOG_LVL_SQL);

            $test->debugOff();
            
            $test->setLogLvl(LOG_LVL_DBINTFCE);
            $test->setLogLvl(LOG_LVL_SQL);
            
            $test->trace("Dit is input trace tekst<br />", LOG_LVL_INPUT);
            
            $test->trace("Dit is db interface trace tekst<br />", LOG_LVL_DBINTFCE);
            
            $test->trace("Dit is SQL trace tekst<br />", LOG_LVL_SQL);

            
            
            var_dump($test);
        } catch (Exception $e) {
            echo '<pre>';
            echo $e->getTraceAsString();
            echo '</pre>';
            trigger_error($e->getMessage());
        }
    }

}

?>
